package com.ziru.ziru.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ziru.ziru.pojo.RoomPicture;
import com.ziru.ziru.pojo.RoomTitle;
import com.ziru.ziru.pojo.Rooms;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 缘友一世
 * date 2023/5/28-8:30
 */
@Mapper
public interface RoomsDao extends BaseMapper<Rooms> {
    @Select("select * from rooms " +
            "left join roomtitle r on rooms.room_id = r.room_id " +
            "where room_name  like concat('%',#{tj},'%') order by rooms.${rule}")
    @Results({
            @Result(property = "roomId",column = "room_id"),
            @Result(property="roomName",column="room_name"),
            @Result(property="roomArea",column="room_area" ),
            @Result(property="roomNumber",column="room_number" ),
            @Result( property="roomNumbers", column="room_numbers" ),
            @Result( property="houseType", column="house_type" ),
            @Result( property="floor", column="floor" ),
            @Result( property="roomLocation", column="room_location" ),
            @Result( property="elevator" , column="elevator" ),
            @Result( property="completion" , column="completion" ),
            @Result( property="heatingType", column="heating_type" ),
            @Result( property="afforest" , column="afforest" ),
            @Result( property="areaLocation", column="area_location" ),
            @Result( property="subway", column="subway" ),
            @Result( property="tenementName", column="tenement_name" ),
            @Result( property="roomPrice", column="room_price" ),
            @Result( property="characterName", column="character_name" ),
            @Result( property="orientationName", column="orientation_name" ),
            @Result( property="statusName", column="status_name" ),
            @Result( property="specialOffer", column="special_offer" ),
            @Result( property="roomTime", column="room_time" ),
            @Result( property="videoUrl", column="video_url"),
            @Result( property="roomPic", column="room_pic"),
            @Result( property="uid", column="uid" ),
            @Result(property = "roomTitles",column = "room_id",many = @Many(select = "com.ziru.ziru.dao.RoomsDao.queryRoomtitleById")),
            @Result(property = "roomPictures",column = "room_id",many = @Many(select = "com.ziru.ziru.dao.RoomsDao.queryRoomPictureById"))
    })
    List<Rooms> queryAll(@Param("rule") String rule,@Param("tj") String tj);

    @Select("select * from roomtitle where room_id=#{room_id}")
    List<RoomTitle> queryRoomtitleById();

    @Select(" select * from roompicture where room_id = #{room_id}")
    List<RoomPicture> queryRoomPictureById();

}
